import 'dart:io';
import 'package:shared_preferences/shared_preferences.dart';

class KDevice{
  static int deviceType = 0;
  static String deviceId = '';
  static String token = '';
  static const String token_name = 'Authorization';
  static Future getDeviceType() async{
    if(Platform.isIOS){
      return 2;
    }else if(Platform.isAndroid){
      return 3;
    }
    return 1;
  }
  static Future<Null> _addTokenLocal(token) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setString(KDevice.token_name, token);
  }
}

Future<String> getTokenLocal() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  return prefs.getString(KDevice.token_name);
}
Future<Null> setTokenLocal(token) async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  prefs.setString(KDevice.token_name, token);
}

Future<Null> addParamLocal(key, value) async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  prefs.setString(key, value);
}

Future<Null> removeLocal(key) async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  prefs.remove(key);
}


class DeviceBaseInfo {
  final int deviceType;
  final String deviceId;
  final String appId;
  final String appSecret;
  final int channel;
  DeviceBaseInfo({this.deviceType, this.deviceId, this.appId, this.appSecret, this.channel});

  factory DeviceBaseInfo.fromJson(Map<String, dynamic> json) {
    return DeviceBaseInfo(
      deviceType: json['deviceType'] as int,
      deviceId: json['deviceId'] as String,
      appId: json['appId'] as String,
      appSecret: json['appSecret'] as String,
      channel: json['channel'] as int,
    );
  }


}